package cn.y.operation.framework.mvc;

import cn.y.operation.framework.enums.ResponseMsgEnum;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

import java.io.Serializable;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class ResponseMsg implements Serializable {
    @JsonIgnore
    private static final long serialVersionUID = 1L;
    private Integer status; //返回码  0请求成功 !0 失败
    private String msg; //错误消息
    private Object data;

    public ResponseMsg() {
        super();
    }

    public ResponseMsg(ResponseMsgEnum msgEnum) {
        super();
        this.status = msgEnum.getCode();
        this.msg = msgEnum.getInfo();
    }

    public ResponseMsg(ResponseMsgEnum msgEnum, Object data) {
        super();
        this.status = msgEnum.getCode();
        this.msg = msgEnum.getInfo();
        this.data = data;
    }

    public ResponseMsg(Integer status, String msg) {
        super();
        this.status = status;
        this.msg = msg;
    }

    public ResponseMsg(Integer status, String msg, Object data) {
        super();
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public static ResponseMsg success(String msg) {
        ResponseMsg response = new ResponseMsg();
        response.setStatus(ResponseMsgEnum.SUCCESS.getCode());
        response.setMsg(msg);
        return response;
    }
    public static ResponseMsg data(Object data) {
        ResponseMsg response = new ResponseMsg();
        response.setStatus(ResponseMsgEnum.SUCCESS.getCode());
        response.setData(data);
        return response;
    }

    public static ResponseMsg error(String msg) {
        ResponseMsg response = new ResponseMsg();
        response.setStatus(ResponseMsgEnum.FAIL.getCode());
        response.setMsg(msg);
        return response;
    }

    public static ResponseMsg error(ResponseMsgEnum responseMsgEnum) {
        ResponseMsg response = new ResponseMsg();
        response.setStatus(responseMsgEnum.getCode());
        response.setMsg(responseMsgEnum.getInfo());
        return response;
    }

}
